Constructor for an xml-object
addns - add a namespace definition to the xml-object
obj = addns(obj,S)
obj | xml-object | S: <struct> fieldnames --> namespace variable values --> namespace value <cell array> nx2, first column --> namespace variable second column --> namespace value |
obj | xml-object | EXAMPLE %create an xml-object obj = xml(fullfile(pwd,'examples','namespaces.xml')) %try to get attribute obj.width.('@nsdim:dim') %add namespace addns(obj,{'nsdim','http://www.modelit.nl/dimension'}) %get attribute obj.width.('@nsdim:dim') |
xml/attributeNames is a function. names = attributeNames(obj)
clearns - remove all the namespace definitions from the xml-object
obj = addns(obj,S)
obj | xml-object | S: <struct> fieldnames --> namespace variable values --> namespace value <cell array> size: nx2, first column --> namespace variable second column --> namespace value |
obj: <xml-object> with no namespace definitions EXAMPLE %create an xml-object obj = xml(fullfile(pwd,'examples','namespaces.xml')) %add namespaces addns(obj,{'ns','http://www.w3schools.com/furniture'}) addns(obj,{'nsdim','http://www.modelit.nl/dimension'}) %list namespaces listns(obj) %clear all defined namespaces clearns(obj) %list namespaces listns(obj)
display - display information about an xml-object on the console
display(obj)
obj | xml-object |
none, information about the xml-object is displayed on the console
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) %display function was automatically called by Matlab
fieldNames - get the names of the direct children of the root node c.f. the function fieldnames for structures
fields = fieldnames(obj)
obj | xml-object |
fields: <cellstring> with the nodenames of the children of the root node
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) fieldnames(obj) book1 = obj.book(1) fieldnames(book1{1})
get - get the value of the specified property for an xml-object (from the object itself not from the xml)
prop_val = get(obj,prop_name)
obj | xml-object | prop_name: <string> propertyname, possible values: - DOM <org.apache.xerces.dom.DeferredDocumentImpl> with the DOM representation of the xml - file <string> with filename - NS <java.util.HashMap> with namespaces |
prop_val: the value of the specified property for the xml-object <struct> with all properties plus values if nargin == 1
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) %get all property-value pairs get(obj) %get the (D)ocument (O)bject (M)odel get(obj,'DOM')
getRoot - get the root node of an xml-object and its name
[rootname root] = getRoot(obj)
obj | xml-object |
rootname: <string> the name of the root node root: <java object> org.apache.xerces.dom.DeferredElementNSImpl or org.apache.xerces.dom.DeferredElementImpl
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) [rootname root] = getRoot(obj)
getns - retrieve a namespace definition from the xml-object
S = listns(obj,key)
obj | xml-object | key: <string> with a namespace variable for which the definition has to be retrieved |
S: <string> with the namespace definition EXAMPLE %create an xml-object obj = xml(fullfile(pwd,'examples','namespaces.xml')) %add namespace addns(obj,{'nsdim','http://www.modelit.nl/dimension'}) %get namespace getns(obj,'nsdim')
inspect - visualize the xml document as a tree in a separate window
inspect(obj)
obj | xml-object |
none, the DOM representation of the xml document appears as a tree in a separate window
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) inspect(obj)
isempty - true if the xml-object has no fields
tf = isempty(obj)
obj | xml-object |
tf: <boolean> true if the DOM representation of the xml document does not contain any nodes, or equivalently the xml-document has no fields
%create an empty xml-object obj = xml isempty(obj) %add a field to the xml-object obj.field = 'field' isempty(obj) %remove field from the xml-object rmfield(obj,'field'); isempty(obj)
isfield - true if at least one node satisfies the indexing 'sub'
tf = isfield(obj,field)
obj | xml-object | sub: <string> index into xml document (same format as indexing into Matlab structures) e.g. 'book(1)' or 'book(1).title' result in the same substructs as would be obtained if S.book(1)or S.book(1).title were used (S a Matlab structure) <string> with xpath expression |
tf: <boolean> true if at least one node satisfies the indexing 'sub'
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) isfield(obj,'book(1:2)') isfield(obj,'book(2).@category') %N.B. in the following statement true is return although the number of %books is 4, this is because book(2:4) exist isfield(obj,'book(2:10)') %examples with xpath expression %are there any books in english? isfield(obj,'bookstore/book/title[@lang=''en'']') %are there any books in spanish? isfield(obj,'bookstore/book/title[@lang=''es'']') %are there books cheaper than 30 euro isfield(obj,'bookstore/book[price < 30]')
listns - list the namespace definitions of the xml-object
listns(obj)
obj | xml-object |
no direct output, the defined namespaces are displayed on the console EXAMPLE %create an xml-object obj = xml(fullfile(pwd,'examples','namespaces.xml')) %no namespaces defined yet listns(obj) %add namespaces addns(obj,{'ns','http://www.w3schools.com/furniture'}) addns(obj,{'nsdim','http://www.modelit.nl/dimension'}) %list namespaces listns(obj)
noNodes - get the total number of nodes present in the DOM-representation of the xml document
N = noNodes(obj)
obj | xml-object |
N: <integer> with the total number of nodes in the DOM object
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) noNodes(obj)
removens - remove a namespace definition from the xml-object
obj = removens(obj,S)
obj | xml-object | S: <char array> with names of the namespace definitions to be removed <cell array> with names of the namespace definitions to be removed |
obj | xml-object | EXAMPLE %create an xml-object obj = xml(fullfile(pwd,'examples','namespaces.xml')) %add namespace addns(obj,{'nsdim','http://www.modelit.nl/dimension'}) %get attribute obj.width.('@nsdim:dim') %remove namespace removens(obj,{'nsdim'}) %try to get attribute obj.width.('@nsdim:dim') |
rmfield - remove elements and attributes from an xml-object which satisfy the indexing 'sub'
rmfield(obj,sub)
obj | xml-object | sub: <string> index into xml document (same format as indexing into Matlab structures) e.g. 'book(1)' or 'book(1).title' result in the same substructs as would be obtained if S.book(1)or S.book(1).title were used (S a Matlab structure) <string> with xpath expression |
none, the xml-object is updated
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) rmfield(obj,'book(1:2)') rmfield(obj,'book(2).@category') inspect(obj) %examples with xpath expression obj = xml(fullfile(pwd,'examples','books.xml')) %remove books cheaper than 30 euro rmfield(obj,'bookstore/book[price < 30]') inspect(obj) obj = xml(fullfile(pwd,'examples','books.xml')) %remove books in the category 'WEB' rmfield(obj,'bookstore/book[@category = ''WEB'']') inspect(obj)
save - save the xml-object as an xml file
obj = save(obj,fname)
obj | xml-object | fname: <string> (optional) the name of the xml file, if fname is not specified a save dialog will pop up |
obj: <xml-object> the file field of the xml-object is updated and an xml file is created
obj = xml %create an empty xml object obj.date = datestr(now) %add fields with values obj.description = 'test' obj = save(obj,'test.xml') %save object by specifying filename obj = xml('test.xml') inspect(obj);
selectNodes - select nodes from the XML DOM tree
nodesList = selectNodes(obj,ind)
obj | xml-object | ind: <struct array> with fields - type: one of '.' or '()' - subs: subscript values (field name or cell array of index vectors) <string> with an xpath expression |
nodesList: <java object> java.util.ArrayList with tree nodes
set - set the value of the specified property for an xml-object
set(obj,prop_name,prop_value)
obj | xml-object | prop_name: <string> propertyname, possible values: - DOM <org.apache.xerces.dom.DeferredDocumentImpl> with the DOM representation of the xml - file <string> with filename - NS <java.util.HashMap> with namespaces prop_value: the value of the property to be set for the xml-object |
obj: <xml-object> with the property prop_name set to prop_value
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) %get all property-value pairs get(obj,'file') %get the (D)ocument (O)bject (M)odel obj = set(obj,'file',fullfile(pwd,'examples','books_changed.xml')) get(obj,'file')
storeStructure - store contents of structure in xml object
obj = storeStructure(obj,S)
S: <struct> or <struct array>
obj | xml-object |
obj=xml obj = storeStructure(obj,S) inspect(obj) NOTES - This function is called by xml object constructor, in case where constructure is called with a structure as its input argument. - Although alternative uses of this method may be possible, they have not yet been tested
subsasgn - assign new values to the xml document in an xml-object
obj = subsassgn(obj,ind,data)
obj | xml-object | ind: <struct array> with fields - type: one of '.' or '()' - subs: subscript values (field name or cell array of index vectors) <string> with an xpath expression data: (optional) with the values to be put in the by ind defined fields in the xml-object, allowed types: - <struct> matlab structure - <xml-object> - <org.apache.xerces.dom.ElementImpl> |
obj | xml-object |
subsref - subscripted reference for an xml object
S = subsref(obj,ind)
obj | xml-object | ind: <struct array> with fields - type: one of '.' or '()' - subs: subscript values (field name or cell array of index vectors) <string> with an xpath expression |
S: <cell array> with contents of the referenced nodes, can contain xml objects, strings or numbers
view - convert the xml-object into a string Note: This method has been superseeded by the method "xml2str" the method view is kept for backward compability but will become obsolete in the future.
view(obj) S=view(obj)
obj | xml-object |
S: <string> with the xml-document
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) view(obj)
xml - Constructor for an xml-object
obj = xml(FileName, isNameSpaceAware)
FileName | any | string, the name of the sourcefile string, the xml string java-object, a D(ocument) (O)bject (M)odel struct, a Matlab structure |
isNameSpaceAware | any | boolean, (optional) (default == 1) use namespaces |
obj | any | xml-object with fields: - DOM: <java object> the DOM object - file: <string> the name of the xml source - NS: <java object> a hashmap with namespace definitions N.B. obj is empty when an error occurred |
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) inspect(obj) %create an xml from a sourcefile obj = xml(java.io.File(fullfile(pwd,'examples','books.xml'))) inspect(obj) %create an xml from a Matlab structure obj = xml(dir) inspect(obj) %create an xml directly from a string str = '<book category="MATHS"><title lang="en">Nonlinear Programming</title><author>Dimitri P. Bertsekas</author></book>' obj = xml(str) inspect(obj) %create an xml directly from an inputstream obj = xml(java.io.FileInputStream((fullfile(pwd,'examples','books.xml')))) inspect(obj)
xml2str - convert the xml-object into a string Note: This method replaces the method "view" the method view is kept for backward compability
xml2str(obj) S=xml2str(obj)
obj | xml-object | removeEOL: optional boolean, default value: false if true remove ascii codes 10 13 and return string in 1 line |
S: <string> with the xml-document
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) xml2str(obj)
xml2struct - transform xml object to Matlab structure if contents of XML permit this CALL s=xml2struct(obj) s=xml2struct(obj,NOCELL) INPUT obj: XML object NOCELL: if true, do NOT store data in cells. Defaults to false OUTPUT corresponding Matlab structure NOTE not all XML documents can be represented as a Matlab strucure if XML contents do not fit the following error results: "XML contents do not fit in Matlab structure"
xml - constructor for an xml-object
obj = xml(FileName,isNameSpaceAware,isValidating)
FileName: <string> name of the sourcefile <string> the xml string <java-object> with a D(ocument) (O)bject (M)odel <struct> a Matlab structure isNameSpaceAware: <boolean> (optional) (default == 1) ignore namespaces isValidating: <boolean> (optional) (default == 0) validate document
obj: <xml-object> with fields: - DOM: <java object> the DOM object - file: <string> the name of the xml source - NS: <java object> a hashmap with namespace definitions N.B. obj is empty when an error occurred
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) inspect(obj) %create an xml from a sourcefile obj = xml(java.io.File(fullfile(pwd,'examples','books.xml'))) inspect(obj) %create an xml from a Matlab structure obj = xml(dir) inspect(obj) %create an xml directly from a string str = '<book category="MATHS"><title lang="en">Nonlinear Programming</title><author>Dimitri P. Bertsekas</author></book>' obj = xml(str) inspect(obj) %create an xml directly from an inputstream obj = xml(java.io.FileInputStream((fullfile(pwd,'examples','books.xml')))) inspect(obj) %create an xml from a sourcefile and validate against a dtd (specified %in the xml itself obj = xml(fullfile(pwd,'examples','note_dtd.xml'),0,1) %create an xml from a sourcefile and validate against a xsd (specified %in the xml itself obj = xml(fullfile(pwd,'examples','note_xsd.xml'),1,1)
xpath - carry out a set or get for an xml-object using xpath syntax
S = xpath(obj,ind) S = xpath(obj,ind,data)
obj | xml-object | ind: <struct array> with fields - type: one of '.' or '()' - subs: subscript values (field name or cell array of index vectors) <string> with an xpath expression data: (optional) with the values to be put in the by ind defined fields in the xml-object, allowed types: - <struct> matlab structure - <xml-object> - <org.apache.xerces.dom.ElementImpl> |
S: <cell array> in nargin == 2 (get is used) <xml-object> if nargin == 3 (set is used)
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','books.xml')) %select the book with title 'Harry Potter' book = xpath(obj,'parent::/bookstore/book[title="Harry Potter"') inspect(book{1})
xslt - transform the xml-object to html by using a stylesheet
HTMLstring = xslt(obj,xsl,fileName)
obj | xml-object | xsl: <string> filename of the stylesheet fileName: <string> (optional) the name of the file to which the HTML has to be saved |
HTMLstring: <string> to HTML transformed XML string
%create an xml from a sourcefile obj = xml(fullfile(pwd,'examples','cd_catalog.xml')) HTMLstring = xslt(obj,fullfile(pwd,'examples','cd_catalog.xsl')) %display in browser web(['text://' HTMLstring]);